package dcc.component;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.l2fprod.common.swing.JLinkButton;

import dcc.manager.base.Manager;
import dcc.ui.MainWindow;

public class JLinkButtonX extends JLinkButton {

	private MainWindow mainWindow;
	private String managerName;
	private String managerLabel;
	private Manager manager;

	public JLinkButtonX(MainWindow mainWindow, final JPanel rightPanel,
			String managerName) {
		super();
		setForeground(Color.BLUE);
		setBorder(new EmptyBorder(4, 4, 4, 4));
		setFont(new Font("Microsoft YaHei", Font.PLAIN, 14));
		this.mainWindow = mainWindow;
		this.managerName = managerName;
		this.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				callManager(rightPanel);
			}
		});
	}

	public String getManagerName() {
		return this.managerName;
	}

	@Override
	public void setText(String text) {
		super.setText(text);
		managerLabel = text;
	}

	private void callManager(JPanel rightPanel) {
		mainWindow.setTitle(this.managerLabel);
		if (this.manager == null) {
			this.manager = mainWindow.getManagerGroup().call(this.managerName,
					rightPanel);
		} else {
			this.manager.show();
		}
	}
}
